Building a Tip of the Day Application (Part 3): Submitting Tips to the Web Service
Table of Contents
Adding a Style Sheet
Although the Tip of the Day application is rather attractive already,
you can beautify it further by adding a Cascading Style Sheet (CSS)
for the tip text. With a style sheet, you can easily add colors for
the active links on the page or highlight the TipTitle.
To add a Cascading Style Sheet, insert the following code onto the presentation screen,
inside the onClipEvent (load) handler before the final
bracket (}):
var flash_css = new TextField.StyleSheet();
flash_css.setStyle(".text", {fontFamily:'Arial,Helvetica,sans-serif', fontSize:'11px', color:'#000000'});
flash_css.setStyle(".title", {fontFamily:'Arial,Helvetica,sans-serif', fontSize:'16px', color:'#999999', fontWeight:'bold'});
flash_css.setStyle("a", {fontFamily:'Arial,Helvetica,sans-serif', fontSize:'11px', color:'#0000FF'});
flash_css.setStyle("a:hover", {fontFamily:'Arial,Helvetica,sans-serif', fontSize:'11px', color:'#336699'});
this.tip.tip_txt.styleSheet = flash_css;
If you test your SWF file now, you see that the tip text field applies
colors to links on the current tip. To apply additional styles, modify
your code slightly and tell it to use these specific style names. Modify
the code on the getTipByDate_wsc component to something
similar to the following:
on (result) {
var tipObj:Object = this.results;
var tipStr:String = "";
tipStr += "<span class='title'>"+tipObj.TipTitle+"</span><br>";
tipStr += "<i>"+tipObj.TipDateTime+"</i><br>";>
tipStr += "<span class='text'>"+tipObj.TipText+"</span><br>";
if (tipObj.AuthorName.length>0) {
tipStr += tipObj.AuthorName+"<br>";
}
if (tipObj.AuthorEmail.length>0) {
tipStr += "<a href='mailto:"+tipObj.AuthorEmail+"' target='_blank'>"
+tipObj.AuthorEmail+"</a><br>";
}
if (tipObj.AuthorURL.length>0) {
tipStr += "<a href='"+tipObj.AuthorURL+"' target='_blank'>"+tipObj.AuthorURL+"</a><br>";
}
this._parent.tip.tip_txt.text = tipStr;
}
There you have it! You’re finished, and you now know more than you ever wanted to know about building a Tip of the Day web service-based application in Flash MX Professional. You can find the finished file with the source files you downloaded for this tutorial; it’s called tip.fla. If you have any questions on this tutorial, visit the Tip of the Day forum in the forums at www.flashmx2004.com.